load_avg, obtains current system load average

TOP | Up | Pheedbak | Download | Tree | Topic | A-Z | Search | Hot | New


A developer of an application may want to know how busy the processor is prior to launching a process; it might choose to allocate the process to another machine or it might choose to defer the launch to a later time.

Although the kernel keeps track of load average, it provides no interface to programmers who wish to see that information. There is a powerful tool available for situations where there is no interface to a piece of kernel data; the program may read kernel memory directly. This power is accompanied by a certain risk: programs that read kernel memory are unlikely to be portable from one Unix system to another, and they may not even be portable on the same system from one release to another.

The example in this directory may be used as a model of how to browse kernel memory for a useful data element, or the example may be used without modification in your application.

The function that does all the work is named loadAverage(), and it is found in file load_avg.c. An application calling this function must #include load_avg.h. The file main.c contains a trivial driver that calls loadAverage. Makefile puts it all together.

Program load_avg (and any other program calling loadAverage) needs to be installed setuid to root.

Some of your customers will not like installing a program setuid to root. For maximum acceptance, you should:

  1. keep this function in a little, separate program like load_avg, not include it in your main application,
  2. mention this in your release notes,
  3. include a man page, under section (1M), for the program,
  4. include the source for the setuid program in your delivered product,
  5. fail gracefully if the setuid program has been removed,
    and
  6. make really sure the setuid program is not installed world writable.


    Select any combo of files you'd like to send yourself a compressed tar image of. Executables/scripts are indicated with a trailing `*' character. (depending upon the browser, it may be necessary to hold down the Ctrl key to select/deselect disjoint items.)
    a compressed tar image of the above-selected items.
    OR, ...
    a compressed tar image of the entire load_avg directory.

    Copyright © 1995, Silicon Graphics, Inc.